﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarvinsArena.Core;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BattleEngineCommon;

namespace BattleEngine2D
{
	public class Robot : BattleEngineCommon.Robot
	{
        private Rectangle recRobot = new Rectangle(0, 0, 27, 26);
        private Rectangle recGun = new Rectangle(0, 26, 22, 16);
        private Rectangle recRadar = new Rectangle(29, 0, 9, 14);

		public Robot(IRobot robot)
		{
            this.RobotHost = robot.RobotHost;
		}

		public void Draw(SpriteBatch spriteBatch, Texture2D texture, Camera camera)
		{
			Vector2 position = new Vector2((float)this.PositionX, (float)this.PositionY) + camera.Position;

			// Skip out of screen elements
			if (position.X + this.recRobot.Width > camera.Screen.X || position.X < -this.recRobot.Width ||
				position.Y + this.recRobot.Height > camera.Screen.Y || position.Y < -this.recRobot.Height)
				return;

            Vector2 originRobot = new Vector2(this.recRobot.Width, this.recRobot.Height) / 2;
            Vector2 originGun = new Vector2(this.recGun.Width, this.recGun.Height) / 2;

			spriteBatch.Draw(texture, position, this.recRobot, this.TeamColor,
                             (float)this.Rotation, originRobot, 1, SpriteEffects.None, 0);
			spriteBatch.Draw(texture, position, this.recGun, Color.White,
                             (float)this.RotationGun, originGun, 1, SpriteEffects.None, 0);
			spriteBatch.Draw(texture, position, this.recRadar, Color.White,
                             (float)this.RotationRadar, originRobot, 1, SpriteEffects.None, 0);
		}
	}
}
